package com.yunang.officialweb.controller;

import com.yunang.officialweb.common.R;
import com.yunang.officialweb.entity.TotalDesc;
import com.yunang.officialweb.service.HomeService;
import com.yunang.officialweb.service.NewsService;
import com.yunang.officialweb.service.TotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author duan
 * @date 2022/12/1 12:14
 */
@RestController
@RequestMapping("/OfficialWebsite")
public class HomeController {
    @Autowired
    private HomeService homeService;

    @Autowired
    private TotalService totalService;

    @RequestMapping(value = "/getCompanyIntroduce", method = RequestMethod.GET)
    public R getHome(){
        return R.ok(homeService.getCompanyIntroduce());
    }

    @RequestMapping(value = "/updateCompanyIntroduce", method = RequestMethod.PUT)
    public R updateHome(@RequestParam(required = false) String chineseName,
                        @RequestParam(required = false) String desc1,
                        @RequestParam(required = false) MultipartFile file){
        TotalDesc totalDesc = new TotalDesc();
        totalDesc.setChineseName(chineseName);
        totalDesc.setDesc1(desc1);
        totalDesc.setImage(totalService.savePic(file, "D://YunAng-web//home//comInt//"));
        return R.ok(homeService.updateCompanyIntroduce(totalDesc));
    }

    @RequestMapping(value = "/getCompanyServices", method = RequestMethod.GET)
    public R getCompanyServices(){
        return R.ok(homeService.getCompanyServices());
    }

    @RequestMapping(value = "/updateCompanyServices", method = RequestMethod.PUT)
    public R updateCompanyServices(@RequestParam String englishName,
                                   @RequestParam String chineseName,
                                   @RequestParam String text){
        TotalDesc totalDesc = new TotalDesc();
        totalDesc.setEnglishName(englishName);
        totalDesc.setChineseName(chineseName);
        totalDesc.setText(text);
        return R.ok(homeService.updateCompanyServices(totalDesc));
    }

    @RequestMapping(value = "/getAboutUs", method = RequestMethod.GET)
    public R getAboutUs(){
        return R.ok(homeService.getAboutUs());
    }

    @RequestMapping(value = "/updateAboutUs", method = RequestMethod.PUT)
    public R updateAboutUs(@RequestParam(required = false) String englishName,
                           @RequestParam(required = false) String chineseName,
                           @RequestParam(required = false) String desc,
                           @RequestParam(required = false) MultipartFile file){
        TotalDesc totalDesc = new TotalDesc();
        totalDesc.setEnglishName(englishName);
        totalDesc.setChineseName(chineseName);
        totalDesc.setDesc1(desc);
        totalDesc.setImage(totalService.savePic(file, "D://YunAng-web//home//aboutUs//"));
        return R.ok(homeService.updateAboutUs(totalDesc));
    }

    @RequestMapping(value = "/getExcellentNumber", method = RequestMethod.GET)
    public R getExcellentNumber(){
        return R.ok(homeService.getExcellentNumber());
    }

    @RequestMapping(value = "/updateExcellentNumber", method = RequestMethod.PUT)
    public R updateExcellentNumber(@RequestParam String englishName,
                           @RequestParam String chineseName,
                           @RequestParam String desc){
        TotalDesc totalDesc = new TotalDesc();
        totalDesc.setEnglishName(englishName);
        totalDesc.setChineseName(chineseName);
        totalDesc.setDesc1(desc);
        return R.ok(homeService.updateExcellentNumber(totalDesc));
    }
}
